package com.list;

import java.util.ArrayList;  
import java.util.List;  
  
import android.app.ListActivity;  
import android.content.Intent;  
import android.database.Cursor;    
import android.net.Uri;  
import android.os.Bundle;  
import android.provider.MediaStore;  
import android.view.View;  
import android.view.View.OnClickListener;
import android.widget.AdapterView;  
import android.widget.AdapterView.OnItemClickListener;  
import android.widget.ArrayAdapter;  
import android.widget.Button;
import android.widget.ListView;  
import android.widget.Toast;  
  
public class main extends ListActivity {  
    public static List<String> songs = new ArrayList<String>();  
    public static List<String> dataSongs = new ArrayList<String>();
	//private Button grabar;  
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);    
        final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;  
        final String[] cursor_cols = {  
                MediaStore.Audio.Media._ID,  
                MediaStore.Audio.Media.ARTIST,  
                MediaStore.Audio.Media.ALBUM,  
                MediaStore.Audio.Media.TITLE,   
                MediaStore.Audio.Media.DATA,  
        };  
        final String where = MediaStore.Audio.Media.IS_MUSIC + "=1"  ;  
        final Cursor cursor = getContentResolver().query(uri, cursor_cols, where, null, null);  
        //cursor.moveToNext();  
  
        while (cursor.moveToNext()) {  
            String artist = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));  
            String album = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));  
            String track = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));  
            String data = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));  
            doSomethingHere(artist, album, track, data);  
        }  
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, songs));  
        getListView().setTextFilterEnabled(true);  
  
        ListView lv = getListView();  
        lv.setTextFilterEnabled(true);  
  
        lv.setOnItemClickListener(new OnItemClickListener() {  
  
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {  
                Intent mediaPlayer = new Intent(main.this, MP.class);  
                mediaPlayer.putExtra("index", String.valueOf(arg2));  
                startActivity(mediaPlayer);  
  
                Toast.makeText(main.this, String.valueOf(arg2), 2000).show();  
  
            }  
        });  
  
    }  
  
private void doSomethingHere(String artist, String album, String track, String data) {  
        songs.add("\n Artist : "+artist+"\n Album : "+album+"\n Track :" +track);  
        dataSongs.add(data);  
  
    }



}  
  